package homework.day03;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Random;

/**
 * 生成10个0-100之间的不重复的随机数,并输出
 *
 * @author Xiloer
 */
public class Test03 {
    public static void main(String[] args) {
        //方法一:
        Random rd = new Random();
        Collection c = new ArrayList();
        for (int i = 0; i < 10; ) {
            int rdnum = rd.nextInt(100);
            if (!c.contains(rdnum)) {
                c.add(rdnum);
                i++;
            }
        }
        System.out.println(c);
        //方法二:
        List<Integer> list = new ArrayList();
        while (list.size() < 10) {
            int n = rd.nextInt(100);
            if (!list.contains(n)) {
                list.add(n);
            }
        }
        System.out.println(list);
    }
}
